#!/bin/bash -eux

value="$(action-get value)"

if [ -n "${value}" ]; then
    for relation_id in $(relation-ids sink); do
        relation-set -r $relation_id --app app-token="$JUJU_UNIT_NAME $value"
    done
    status-set active "Token is $(echo $value | cut -c 1-20)" || true
    action-set set-app-token.value="$JUJU_UNIT_NAME ${value}"
else
    action-set set-app-token.value=""
fi

action-set outcome="success"
